package org.nstack.header.storage.primary;

import org.springframework.http.HttpMethod;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;


@RestRequest(
        path = "/primary-storage/{uuid}/actions",
        isAction = true,
        responseClass = APIChangePrimaryStorageStateEvent.class,
        method = HttpMethod.PUT
)
public class APIChangePrimaryStorageStateMsg extends APIMessage implements PrimaryStorageMessage {

    @APIParam(resourceType = PrimaryStorageVO.class)
    private String uuid;

    @APIParam(validValues = {"enable", "disable", "maintain", "deleting"})
    private String stateEvent;

    public APIChangePrimaryStorageStateMsg(String uuid, String stateEvent) {
        super();
        this.uuid = uuid;
        this.stateEvent = stateEvent;
    }

    public APIChangePrimaryStorageStateMsg() {
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    @Override
    public String getPrimaryStorageUuid() {
        return getUuid();
    }

    public String getStateEvent() {
        return stateEvent;
    }

    public void setStateEvent(String stateEvent) {
        this.stateEvent = stateEvent;
    }
 
    public static APIChangePrimaryStorageStateMsg __example__() {
        APIChangePrimaryStorageStateMsg msg = new APIChangePrimaryStorageStateMsg();

        msg.setUuid(uuid());
        msg.setStateEvent(PrimaryStorageState.Disabled.toString());

        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                if (evt.isSuccess()) {
                    ntfy("Changed the state").resource(uuid, PrimaryStorageVO.class.getSimpleName())
                            .messageAndEvent(that, evt).done();
                }
            }
        };
    }

}
